//
//  LpCustomSearchView.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 17/5/6.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LpCustomSearchView.h"
#import "LPCoustomFortyFourImageViewAndLabelView.h"
@interface LpCustomSearchView ()<LpCoustomFortyFourDelegate>
/**  搜索  */
@property (strong, nonatomic) UILabel  *searchLabel;
/**  搜索图片  */
@property (strong, nonatomic) UIImageView  *searImageView;

/**  左边视图  */
@property (strong, nonatomic) LPCoustomFortyFourImageViewAndLabelView  *leftView;
/**  右边视图  */
@property (strong, nonatomic) LPCoustomFortyFourImageViewAndLabelView  *rightView;


@end

@implementation LpCustomSearchView
- (instancetype)initWithFrame:(CGRect)frame leftImage:(NSString *)leftImageString
                   leftString:(NSString *)leftString rightImage:(NSString *)rightImageString rightString:(NSString *)rightString
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor themeColor];
        [self addSubview:self.leftView];
        [self addSubview:self.rightView];
        [self addSubview:self.searchLabel];
        [self.searchLabel addSubview:self.searImageView];
        self.leftView.imageView.image = [UIImage imageNamed:leftImageString];
        self.leftView.label.text = leftString;
        
        self.rightView.imageView.image = [UIImage imageNamed:rightImageString];
        self.rightView.label.text = rightString;
        
    }
    return self;
}


#pragma mark - LpCoustomFortyFourDelegate
- (void)lpFortyFourWithView:(LPCoustomFortyFourImageViewAndLabelView *)view click:(BOOL)click{
    if (self.delegate && [self.delegate respondsToSelector:@selector(lpCustomSearchWithView:index:)]) {
        [self.delegate lpCustomSearchWithView:self index:view.tag];
    }
}

/**  输入框的点击事件  */
- (void)tapClick:(UITapGestureRecognizer *)tap{
    if (self.delegate && [self.delegate respondsToSelector:@selector(lpCustomTapTextFieldWithView:click:)]) {
        [self.delegate lpCustomTapTextFieldWithView:self click:YES];
    }

}


- (LPCoustomFortyFourImageViewAndLabelView *)leftView{
    if (!_leftView) {
        _leftView = [[LPCoustomFortyFourImageViewAndLabelView alloc] initWithFrame:CGRectMake(0, 0, 50 * [UIScreen zj_screenWScale], 44)];
        _leftView.delegate = self;
        _leftView.tag = 100;
    }
    return _leftView;
}

- (LPCoustomFortyFourImageViewAndLabelView *)rightView{
    if (!_rightView) {
        _rightView = [[LPCoustomFortyFourImageViewAndLabelView alloc] initWithFrame:CGRectMake([UIScreen zj_screenWith] - 50 * [UIScreen zj_screenWScale], 0, 50 * [UIScreen zj_screenWScale], 44)];
        _rightView.delegate = self;
        _rightView.tag = 101;
    }
    return _rightView;
}

- (UIImageView *)searImageView{
    if (!_searImageView) {
        _searImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.searchLabel.width - 28, 4, 20, 20)];
        _searImageView.contentMode = UIViewContentModeCenter;
        _searImageView.image = [UIImage imageNamed:@"home_icon_search"];
    }
    return _searImageView;
}


- (UILabel *)searchLabel{
    if (!_searchLabel) {
        _searchLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(55 * [UIScreen zj_screenWScale], 8, [UIScreen zj_screenWith] - 110 * [UIScreen zj_screenWScale], 28)];
            label.textAlignment = NSTextAlignmentLeft;
            label.text = @"   输入关键字快速查找内容";
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor whiteColor];
            label.userInteractionEnabled  = YES;;
            label.layer.cornerRadius = 12;
            label.layer.masksToBounds = YES;
            label.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
            [label addGestureRecognizer:tap];
            label;
        });
    }
    return _searchLabel;
}



@end
